package com.sangfor.ssl.service.utils;

import android.os.ParcelFileDescriptor;
import com.sangfor.ssl.service.https.HttpRequest;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.zip.ZipFile;

/* loaded from: classes2.dex */
public class IOUtils {
    public static final int DEFAULT_BUFFER_SIZE = 4096;
    public static final int EOF = -1;

    public static String readStringFully(InputStream inputStream, String str) throws IOException {
        byte[] bArr = new byte[4096];
        ByteArrayOutputStream byteArrayOutputStream = null;
        try {
            ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream(4096);
            while (true) {
                try {
                    int read = inputStream.read(bArr);
                    if (read > 0) {
                        byteArrayOutputStream2.write(bArr, 0, read);
                    } else {
                        String byteArrayOutputStream3 = byteArrayOutputStream2.toString(str);
                        closeQuietly((OutputStream) byteArrayOutputStream2);
                        return byteArrayOutputStream3;
                    }
                } catch (Throwable th) {
                    th = th;
                    byteArrayOutputStream = byteArrayOutputStream2;
                    closeQuietly((OutputStream) byteArrayOutputStream);
                    throw th;
                }
            }
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public static void closeQuietly(InputStream inputStream) {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException unused) {
            }
        }
    }

    public static void closeQuietly(OutputStream outputStream) {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException unused) {
            }
        }
    }

    public static void closeQuietly(ZipFile zipFile) {
        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException unused) {
            }
        }
    }

    public static void closeQuietly(HttpRequest httpRequest) {
        if (httpRequest != null) {
            try {
                httpRequest.close();
            } catch (IOException unused) {
            }
        }
    }

    public static void closeQuietly(Socket socket) {
        if (socket != null) {
            try {
                socket.close();
            } catch (IOException unused) {
            }
        }
    }

    public static void closeQuietly(ParcelFileDescriptor parcelFileDescriptor) {
        if (parcelFileDescriptor != null) {
            try {
                parcelFileDescriptor.close();
            } catch (IOException unused) {
            }
        }
    }

    @Deprecated
    private static void closeQuietly(Closeable closeable) {
        throw new UnsupportedOperationException("Don't invoke closeQuietly(Closeable res)!");
    }
}
